﻿using CatUtils.Utils.Currency.IoUtils;

using CatUtils.Utils.SpecialUtils.View;
using RabbitDownload.Helper;

using System;
using System.Windows.Forms;

namespace RabbitDownload.WebSite.WebCurrency
{
    public partial class AlertSplitList : Form
    {
        public AlertSplitList()
        {
            InitializeComponent();

            InItData();
        }

        private void InItData()
        {
            count = 10;
            label1.Text = "保存文件为lst格式，迅雷支持直接打开，\r\n一次最多1000个文件,故需要切割。";
            if (SaveHelper.TempPath != "")
                label2.Text = string.Format("猜测您要保存：\r\n{0}\r\n如正确请使用快速切割。", FileNameHelper.GetFileName(SaveHelper.TempPath));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WebSiteHelper.SelcetSplit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            StaticValueOld.AutosaveImgListFlag = false;
            FastSplit();
        }

        /// <summary>
        /// 切割
        /// </summary>
        private void FastSplit()
        {
            String FloderPath = WebSiteHelper.ListSplit(SaveHelper.TempPath);
            if (FloderPath != "" && !StaticValueOld.AutosaveImgListFlag)
                FloderHelper.OpenFloder(FloderPath);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(Helper.StaticValueOld.SaveListPath);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            FloderHelper.FolderDelete(StaticValueOld.SaveListPath);
            FloderHelper.FolderCreate(StaticValueOld.SaveListPath);
            MessageHelper.Alert("已清理全部垃圾");
        }

        private int count = 10;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (count >= 0)
            {
                label3.Text = string.Format("距离自动处理还有{0}秒", count--);
            }
            else
            {
                if (StaticValueOld.AutosaveImgListFlag)
                {
                    Console.WriteLine("运行结束");
                    Close();
                }
                else
                {
                    label3.Text = "未预设动作，不处理。";
                }
            }
        }
    }
}